<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace Rtgm\smecc\SM2;

class Hex2ByteBuf
{
    public static function ConvertGmp2ByteArray($GmpData)
    {
        $HexStr = gmp_strval($GmpData, 16);
        $OutBuf = [];
        $OutBuf = Hex2ByteBuf::HexStringToByteArray($HexStr);
        return $OutBuf;
    }
    public static function ByteArrayToHexString($b, $nlen = NULL)
    {
        $outstring = [];
        $nlen = $nlen == NULL ? count($b) : 0;
        for ($n = 0; $n < $nlen; $n++) {
            $outstring[] = Hex2ByteBuf::myhex($b[$n]);
        }
        return implode("", $outstring);
    }
    private static function myhex($indata)
    {
        $temp_1 = $indata / 16;
        if($temp_1 < 10) {
            $temp_1 = $temp_1 + 48;
        } else {
            $temp_1 = $temp_1 + 65 - 10;
        }
        $temp_2 = $indata % 16;
        if($temp_2 < 10) {
            $temp_2 = $temp_2 + 48;
        } else {
            $temp_2 = $temp_2 + 65 - 10;
        }
        return chr($temp_1) . chr($temp_2);
    }
    public static function HexStringToByteArray($InString)
    {
        for ($m = strlen($InString); $m < 64; $m++) {
            $InString = "0" . $InString;
        }
        $g_len = 0;
        $nlen = 0;
        $n = 0;
        $i = 0;
        $temp = "";
        $nlen = strlen($InString);
        if($nlen < 16) {
            $g_len = 16;
        }
        $g_len = $nlen / 2;
        $n = 0;
        while ($n < $nlen) {
            $temp = substr($InString, $n, 2);
            $temp = "0x" . $temp;
            $b[$i] = hexdec($temp);
            $i = $i + 1;
            $n = $n + 2;
        }
        return $b;
    }
    public static function HexStringToByteArray2($InString)
    {
        $g_len = 0;
        $nlen = 0;
        $n = 0;
        $i = 0;
        $temp = "";
        $nlen = strlen($InString);
        if($nlen < 16) {
            $g_len = 16;
        }
        $g_len = $nlen / 2;
        $n = 0;
        while ($n < $nlen) {
            $temp = substr($InString, $n, 2);
            $temp = "0x" . $temp;
            $b[$i] = hexdec($temp);
            $i = $i + 1;
            $n = $n + 2;
        }
        return $b;
    }
}

?>